package fun._6742.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import fun._6742.service.AddressService;
import fun._6742.service.AdminOrderService;

import javax.annotation.Resource;

@Api(tags = "订单管理")
@RestController
@RequestMapping("api/admin/order/v1")
public class AdminOrderController {

    @Resource
    AdminOrderService adminOrderService;
    @Resource
    AddressService addressService;


    @ApiOperation(value = "订单列表")
    @GetMapping("/")
    public Object listAllOrder(@ApiParam(value = "id") @RequestParam(value = "id", defaultValue = "-1") long id,
                               @ApiParam(value = "当前页") @RequestParam(value = "page", defaultValue = "1") int page,
                               @ApiParam(value = "每页显示条数") @RequestParam(value = "size", defaultValue = "10") int size,
                               @ApiParam(value = "订单是否完成,0未完成,1已完成,2取消,默认所有") @RequestParam(value = "status", defaultValue = "-1") int status) {
        if (id > 0) {
            return adminOrderService.findOne(id, status);
        } else {
            return adminOrderService.listAll(page, size, status);
        }
    }

    @ApiOperation(value = "订单地址")
    @GetMapping("/address/{id}")
    public Object findAddress(@ApiParam(value = "id") @PathVariable(value = "id") long id) {
        return addressService.queryDetail(id);
    }


    @ApiOperation(value = "订单状态设置")
    @PutMapping("/{id}")
    public void changeOrderStatus(@ApiParam(value = "id") @PathVariable(value = "id") long id,
                                  @ApiParam(value = "0未完成,1已完成,2取消") @RequestParam(value = "status", defaultValue = "-1") int status) {
        adminOrderService.changeStatus(id, status);
    }
}
